#include <QCoreApplication>
#include <QtXml>
#include <QFile>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QDomDocument document;

    QDomElement root = document.createElement("Dorms");
    document.appendChild(root);

    for (int i = 0; i < 5; ++i){
        QDomElement dorm = document.createElement("Drom");
        dorm.setAttribute("ID", QString::number(i));
        dorm.setAttribute("Name", "Drom Building " + QString::number(i));
        root.appendChild(dorm);

        for (int j = 0; j < 3; ++j){
            QDomElement room = document.createElement("Room");
            room.setAttribute("Name:", "Room " + QString::number(j));
            room.setAttribute("ID: ", QString::number(j));
            dorm.appendChild(room);
        }
    }

    QFile file("/home/luchu/myXML.xml");
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)){
        qDebug() << "Could not open file: " << file.errorString();
    }else{
        QTextStream stream(&file);
        stream << document.toString();
        qDebug() << document.toString();
        qDebug() << "Write Finished.";
        file.flush();
        file.close();
    }

    return a.exec();
}
